<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组练习</title>

    <script type="text/javascript">
        function Person(name, age, gender) {
            this.name = name;
            this.age = age;
        }

        // 修改Person的原型的toString
        Person.prototype.toString = function() {
            return "Person[name = " + this.name +", age = " + this.age + "]"
        }
        
        // 创建一个对象
        var per = new Person("孙悟空", 100);
        var per2 = new Person("齐天大圣", 100);
        var per3 = new Person("猪八戒", 90);
        var per4 = new Person("牛魔王", 150);
        var per5 = new Person("红孩儿", 10);

        var perArr = [per, per2, per3, per4, per5];

        // 创建一个函数,可以将perArr中的满18岁的Person提取出来，然后封装到一个新的数组中并返回
        function getAdult(arr) {
            var newArr = [];
            for (var i = 0; i < arr.length; i++) {
                if(arr[i].age > 100)
                    newArr.push(arr[i])
            }
            return newArr;
        }

        var res = getAdult(perArr);
        console.log(res);

        // forEach循环

        perArr.forEach(function(value, index, obj) {
            console.log(value);
        });

    </script>


</head>
<body>
    
</body>
</html>